<extend name="Public:template" />
<block name="page_header">
	<include file="Public:header_cust"/>
</block>
<block name="page_body">
	<div class="row">
		<div class="span4">
			<include file="Public:left_menu_cust"/>
		</div>
		<div class="span16">
			<include file="Public:breadcrumb_cust"/>
		</div>
		<volist name="list" id="val">
		<div class="span8">
			<table class="table table-bordered">
				<tr>
					<th class="alert-warning text-left" style="font-size:14px"><img class="img-thumbnail" src="__ROOT__/statics/mobile/images/icons/house.png"><span id="address{$val.id}">{$val.address}</span></th>
				</tr>
				<tr>
					<td class="text-left">
						<form action="{:U('CustAddress/doUpd')}" method="post" id="form_upd{$val.id}" name="form_upd{$val.id}" role="form">
							<input type="hidden" name="id" value="{$val.id}">
							<div class="input-prepend">
								<span class="btn alert-success"><i class="icon-user"></i></span>
								<input type="text" class="input-xlarge" name="name" value="{$val.name}" placeholder="请输入收货人姓名">
							</div>
							<div class="input-prepend">
								<span class="btn alert-success"><i class="icon-hdd"></i></span>
								<input type="text" class="input-xlarge" name="mobile" value="{$val.mobile}" placeholder="请输入收货人手机或电话">
							</div>
							<div class="input-prepend">
								<span class="btn alert-success"><i class="icon-home"></i></span>
								<input type="text" class="input-xlarge" name="address" value="{$val.address}" placeholder="请输入您的收货地址">
							</div>
							<div class="checkbox mt15">
								<label>
									<input type="checkbox"  name="is_default" value="1" <if condition="$val['is_default'] eq 1">checked</if>>常用地址
								</label>
							</div>
						</form>
					</td>
				</tr>
				<tr>
					<td>
						<button type="button" class="btn btn-warning  pull-right" style="width:140px" onClick="doUpd('{$val.id}')"><span class="icon-white icon-pencil"></span>更 新 </button>
						<button type="button" class="btn btn-default active  pull-left" onClick="doDel('{$val.id}')"><span class="icon icon-trash"></span>删除</button>
					</td>
				</tr>
			</table>
		</div>
		</volist>
		<div class="span8">
			<table class="table table-bordered">
				<tr>
					<th class="alert-success text-left" style="font-size:14px"><img class="img-thumbnail" src="__ROOT__/statics/mobile/images/icons/add_green.png" style="margin-right:5px">添加新地址</th>
				</tr>
				<tr>
					<td class="text-left">
						<form action="{:U('CustAddress/doAdd')}" method="post" id="form_add" name="form_add" role="form">
							<div class="input-prepend">
								<span class="btn alert-success"><i class="icon-user"></i></span>
								<input type="text" class="input-xlarge" name="name" value="{$cust.name}" placeholder="请输入收货人姓名">
							</div>
							<div class="input-prepend">
								<span class="btn alert-success"><i class="icon-hdd"></i></span>
								<input type="text" class="input-xlarge" name="mobile" value="{$cust.mobile}" placeholder="请输入收货人手机或电话">
							</div>
							<div class="input-prepend">
								<span class="btn alert-success"><i class="icon-home"></i></span>
								<input type="text" class="input-xlarge" name="address" value="" placeholder="请输入您的收货地址">
							</div>
							<div class="checkbox mt15">
								<label>
									<input type="checkbox"  name="is_default" value="1">常用地址
								</label>
							</div>
						</form>
					</td>
				</tr>
				<tr>
					<td>
						<button type="button" class="btn btn-success pull-right" style="width:140px"  onClick="doAdd()"><span class="icon-white icon-plus-sign"></span>添加 </button>
						<button type="button" class="btn btn-default active pull-left"  onClick="doEmpty()"><span class="icon icon-refresh"></span>重置</button>
					</td>
				</tr>
			</table>
		</div>		
	</div>
</block>
<block name="script_footer">
<script type="text/javascript">

function doEmpty(){
	document.forms['form_add'].name.value='';
	document.forms['form_add'].mobile.value='';
	document.forms['form_add'].address.value='';
}
function doUpd(id){
	var formId = "#form_upd"+id;
	$.ajax({
        'url': $(formId).attr("action"),
        'type':"post",
        'dataType': "json",
        'data': $(formId).serialize(),
        'success': function (data) {
        	var error = data['error'];
        	var message = data['message'];
        	if(error=='0'){
        		alert('更新成功！');
        		$("#address"+id).html($(formId).find("input[name='address']").val());
        	}else{
        		alert(message);
        	}
        	
        }
    });
	return false;
}

function doAdd(){
	var msgId = "#msg_info_add";
	var formId = "#form_add";
	$(msgId).hide();
	$.ajax({
        'url': $(formId).attr("action"),
        'type':"post",
        'dataType': "json",
        'data': $(formId).serialize(),
        'success': function (data) {
        	var error = data['error'];
        	var message = data['message'];
        	if(error==0){
        		alert('添加成功！');
        		document.location.href="/CustAddress/index.html";
        	}else{
        		alert(message);
        	}
        	
        }
    });
	return false;
}

function doDel(id){
	if(!confirm("确定删除该配送信息？")){
		return false;
	}
	var msgId = "#msg_info_upd"+id;
	var formId = "#form_upd"+id;
	$.ajax({
		'url': "{:U('CustAddress/doDel')}",
        'type':"post",
        'dataType': "json",
        'data': $(formId).serialize(),
        'success': function (data) {
        	var error = data['error'];
        	var message = data['message'];
        	if(error==0){
        		document.location.href="/CustAddress/index.html";
        	}else{
        		$(msgId).html(message);
            	$(msgId).show();
        	}
        	
        }
    });
	return false;
}
</script>
</block>